# 作者：一只牛吗
# 2025 年02月 04日 03时 49分 55秒
# 1278599690@qq.com
def input_password():
    pwd = input("请输入密码：")
    if len(pwd) >= 8:
        return pwd
    print('主动抛出异常：密码长度必须大于等于8位！')
    # 创建异常对象 - 可使用错误信息字符串作为参数
    ex = Exception('密码长度必须大于等于8位！')
    # 主动抛出异常
    raise ex

  


def consume_balance(balance, amount):
    try:
        assert balance>=amount, '交易失败，余额不足！'
        balance -= amount
        print(f'支付成功，余额为{balance:.2f}元。')
    except AssertionError as e:
        print(e)


def consume_balance_2(balance, amount):
    try:
        if balance < amount:
            raise ValueError('交易失败，余额不足！')
        balance -= amount
        print(f'支付成功，余额为{balance:.2f}元。')
    except ValueError as e:
        print(e)


if __name__ == '__main__':
    # try:
    #     input_password()
    # except Exception as e:
    #     print(e)
    try:
        assert 1==0,'你的程序出错了！qwq'
    except AssertionError as e:
        print(e)

    balance = 100
    # consume_balance(balance, 200)
    # consume_balance(balance, 44.3)
    # consume_balance_2(balance, 200)
    consume_balance_2(balance, 44.3)